<template>
    <div style="min-width:1042px">
       <div v-if="$route.path == '/personalAdmin/newStatistics'">
            <div class="vs-search-box" style="padding: 24px 22px 0 0px;">
                <el-form ref="form" :inline="true" :model="paging" label-width="90px">
                    <el-form-item label="" class="fl-right">
                        <el-button @click="init" >重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                    <el-form-item label="门店">
                        <el-input style="width:240px" v-model="paging.store"></el-input>
                    </el-form-item>
                    <el-form-item label="姓名">
                        <el-input style="width:240px" v-model="paging.name"></el-input>
                    </el-form-item>
                    <el-form-item label="部门">
                        <el-input style="width:240px" v-model="paging.epartment"></el-input>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <div class="operation-box">
                    <el-button
                        class="btn-upload left-auto"
                        :loading="isDerive"
                        size="medium"
                        plain
                    >
                    <input ref="uploadPai" @change="attendanceImport" type="file" name="" id="" /> 导入 </el-button>
                </div>
                <el-table 
                :header-cell-style="{background:'#f5f6f8'}" 
                v-loading="loading" 
                :data="monthList" 
                header-row-class-name="has-gutter-table" 
                style="width: 100%">
                    <el-table-column prop="name" label="姓名" ></el-table-column>
                    <el-table-column prop="number" label="工号" ></el-table-column>
                    <el-table-column prop="epartment" min-width="180px" label="岗位"></el-table-column>
                    <el-table-column prop="store" label="所属门店" min-width="120px"></el-table-column>
                    <el-table-column label="概况" align="center">
                        <el-table-column prop="answer_clock" label="应打卡天数（天）" ></el-table-column>
                        <el-table-column prop="normal" label="正常打卡天数（天）" ></el-table-column>
                        <el-table-column prop="abnormal" label="异常天数（天）" ></el-table-column>
                        <el-table-column prop="should_work_time" label="标准工作时长（小时）" ></el-table-column>
                        <el-table-column prop="actual_work_time" label="实际工作时长（小时）" ></el-table-column>
                    </el-table-column>
                    <el-table-column label="异常统计" align="center">
                        <el-table-column prop="abnormal_total" label="异常合计（次）" ></el-table-column>
                        <el-table-column prop="late_number" label="迟到次数（次）" ></el-table-column>
                        <el-table-column prop="late_time" label="迟到时长（分钟）" ></el-table-column>
                        <el-table-column prop="out_number" label="早退次数（次）" ></el-table-column>
                        <el-table-column prop="out_time" label="早退时长（分钟）" ></el-table-column>
                        <el-table-column prop="absenteeism_number" label="旷工次数（次）" ></el-table-column>
                        <el-table-column prop="absenteeism_time" label="旷工时长（分钟）" ></el-table-column>
                        <el-table-column prop="missing_card" label="缺卡次数（次）" ></el-table-column>
                        <el-table-column prop="addres_abnormal" label="地点异常（次）" ></el-table-column>
                        <el-table-column prop="equipment_abnormal" label="设备异常（次）" ></el-table-column>
                    </el-table-column>
                    <el-table-column label="假勤情况" align="center">
                        <el-table-column prop="clock_supplement" label="补卡次数（次）" ></el-table-column>
                        <el-table-column prop="field_personnel" label="外勤次数（次）" ></el-table-column>
                        <el-table-column prop="go_out" label="外出（小时）" ></el-table-column>
                        <el-table-column prop="business_travel" label="出差（天）" ></el-table-column>
                        <el-table-column prop="annual_leave" label="年假（小时）" ></el-table-column>
                        <el-table-column prop="compassionate_leave" label="事假（小时）" ></el-table-column>
                        <el-table-column prop="sick_leave" label="病假（小时）" ></el-table-column>
                        <el-table-column prop="compensatory_leave" label="调休假（小时）" ></el-table-column>
                        <el-table-column prop="marriage_leave" label="婚假（小时）" ></el-table-column>
                        <el-table-column prop="maternity_leave" label="产假（小时）" ></el-table-column>
                        <el-table-column prop="paternity_leave" label="陪产假（小时）" ></el-table-column>
                        <el-table-column prop="other_leave" label="其他（小时)" ></el-table-column>
                    </el-table-column>
                    <el-table-column label="加班情况" align="center">
                        <el-table-column prop="weekdays" label="工作日（小时）" ></el-table-column>
                        <el-table-column prop="holiday" label="节假日（小时）" ></el-table-column>
                        <el-table-column prop="rest" label="休息日（小时）" ></el-table-column>
                    </el-table-column>

                    <!-- <el-table-column label="假勤情况" align="center">
                        <el-table-column prop="compassionate_leave_day" label="事假" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.compassionate_leave_day">
                                    {{ scope.row.compassionate_leave_day }}天数
                                </span>
                                {{ scope.row.compassionate_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="病假" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.sick_leave_day">
                                    {{ scope.row.sick_leave_day }}天数
                                </span>
                                {{ scope.row.compassionate_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="婚假" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.marriage_leave_day">
                                    {{ scope.row.marriage_leave_day }}天数
                                </span>
                                {{ scope.row.marriage_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="产假" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.aternity_leave_day">
                                    {{ scope.row.aternity_leave_day }}天数
                                </span>
                                {{ scope.row.aternity_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="陪产假" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.paternity_leave_day">
                                    {{ scope.row.paternity_leave_day }}天数
                                </span>
                                {{ scope.row.paternity_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                        <el-table-column prop="name" label="其他" >
                            <template slot-scope="scope">
                                <span v-if="scope.row.other_leave_day">{{ scope.row.other_leave_day }}天数</span>
                                {{ scope.row.other_leave_time | timeNum }}
                            </template>
                        </el-table-column>
                    </el-table-column> -->
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination
                        @current-change="handleCurrentChange"
                        :current-page.sync="paging.page"
                        :page-size="paging.limit"
                        layout="prev, pager, next, jumper"
                        :total="paging.total">
                    </el-pagination>
                </div>
            </div>

       </div>
       <router-view></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            statistics:true,
            paging:{
                store:'',
                name:'',
                epartment:'',
                page:1,
                total:0,
                limit:10,
            },
            today:'',
            loading:false,
            shopList:[],
            dayList:[],
            monthList:[],
            positionList:[],
            classesList:[],
            leaveTypeList:[],
            tableData: [],
            isDerive:false,
            isDerive2:false
        };
    },
    created() {
        // let date = new Date();
        // this.today = `${date.getFullYear()}-${date.getMonth()+1}`
        // this.paging.date = this.today;
        // this.homegetStore();
        // this.homegetPosition();
        // this.staffshiftType();
        // this.getleaveType();
        this.getList();
    },
    filters:{
        leaveAnomaly(val){
            if(val.staff_leave){
                return '请假 '
            } else if(val.is_absenteeism){
                return `旷工 ${val.late_time?val.late_time+'分钟':''}`
            } else if(val.is_late){
                return `迟到 ${val.late_time}分钟`
            } else if(val.is_out){
                return `早退 ${val.out_time}分钟`
            }
            return '--';
        },
        timeNum(val){
            if(!val)return '';
            let day = Number.parseInt(val/60);
            let time = val%60;
            return (day?day+'小时':'') +(time?time+'分钟':'')
        }
    },
    methods: {
        async attendanceImport(e){
            let file = e.target.files[0];
            if (!file) return;
            this.isDerive = true;
            this.$refs.uploadPai.value = "";
            console.log(file,'filefilefilefile');
            let { code, data } = await this.$Http.attendanceImport({ files: file }, true);
            this.isDerive = false;
            if (code) {
                this.$message.success('导入成功!')
                this.init(1);
            }
        },
        async derive(){
            this.isDerive = true;
            let res = await this.$Http.attendanceStatisticsExport(this.paging);
            this.utils.downloadXlsx(res,'考勤日统计')
            this.isDerive = false;
        },
        async derive2(){
            this.isDerive2 = true;
            let res = await this.$Http.attendanceStatisticsMonthExport(this.paging);
            this.utils.downloadXlsx(res,'考勤月统计')
            this.isDerive2 = false;
        },
        statChange(e){//

        },
        init(val){
            this.paging = this.$options.data().paging;
            this.handleCurrentChange(1)
        },
        //获取班次类型
        async getleaveType(){
            let {code,data} = await this.$Http.getleaveType();
            if(code){
                this.leaveTypeList = data;
            }
        },
        //获取班次
        async staffshiftType(){
            if(!this.paging.store_id)return;
            let {code,data} = await this.$Http.staffshiftType({
                store_id:this.paging.store_id,
            });
            if(code){
                this.classesList = data;
            }
        },
        // 获取岗位
        async homegetPosition() {
            let { code, data } = await this.$Http.homegetPosition();
            if (code) {
                this.positionList = data;
            }
        },
        async attendanceStatistics(){
            
        },
        async homegetStore(){
            let {code,data} = await this.$Http.homegetStore();
            if(code){
                this.shopList = data;
            }
        },
        handleCurrentChange(val){
            this.paging.page = val;
            this.getList()
        },
        async getList(){
            this.loading = true;
            let obj = {...this.paging};
            var {code,data} = await this.$Http.attendanceImportList(obj);
            this.loading = false;
            if(code){
                console.log(data,'data');
                this.monthList = data.data;
                this.paging.total = data.total;
            }
        },
        pickerDate(){

        },
        change(){

        }
    },
};
</script>

<style lang="scss" scoped>
::v-deep{
    .el-table{
        overflow: inherit;
        td{
            padding: 0;
        }
    }
    .el-table__header-wrapper{
        position: sticky;
        top: 0;
        width: 100%;
        z-index: 99;
    }
    // .el-table__body-wrapper{
    //     height: 80vh;
    //     overflow: auto;
    // }
}
.statistics{
    padding-bottom:20px;
    display: flex;
    justify-content: center;
}
.image-thumbnail{
    width: 130px;
    height: 130px;
}

.btn-upload {
  position: relative;
  overflow: hidden;
  input[type="file"] {
    width: 100%;
    cursor: pointer;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0;
  }
  input[type="file"]::-webkit-file-upload-button {
    cursor: pointer;
  }
}
</style>